index.html.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <ShopPageHead></ShopPageHead>
  3. <main class="index_main" id="all_vue">
  4. <HomeAdvertising :imgurl="adImg1"></HomeAdvertising>
  5. <!--子菜单和地区选择-->
  6. <ShopSubMenu2></ShopSubMenu2>
  7. <!-- 地区选择 -->
  8. <div class="categ_crumb_box clearfix_2">
  9. <!-- 当前位置 -->
  10. <div class="categ_crumb_left">
  11. <span class="categ_crumb_left_a" title=""> 当前位置: </span>
  12. <NuxtLink
  13. :to="`/xiangcunshangcheng/index.html`"
  14. class="categ_crumb_left_a"
  15. >
  16. 乡村商城
  17. </NuxtLink>
  18. &gt;
  19. <span class="categ_crumb_left_text">{{name}}</span>
  20. </div>
  21. <!-- 当前位置 -->
  22. <!-- 当前商品所在地 -->
  23. <div class="categ_crumb_right clearfix" v-if="cityList.length > 0">
  24. <div class="categ_crumb_right_text">当前商品所在地:</div>
  25. <div class="categ_crumb_right_text hand">{{cityName}}</div>
  26. <div class="categ_crumb_right_btn back100 hand" @click="btn_if_categ_crumb_panel_fun" tabindex="1"
  27. @blur="categ_crumb_panel_btn_blur_fun">
  28. </div>
  29. </div>
  30. <!-- 当前商品所在地 -->
  31. <div class="categ_crumb_panel" v-show="if_categ_crumb_panel" tabindex="0"
  32. @click="categ_crumb_panel_focus_fun" @blur="categ_crumb_panel_blur_fun">
  33. <h4 class="categ_crumb_panel_h4">您可以选择以下详细地区</h4>
  34. <div class="categ_crumb_panel_btn_box clearfix">
  35. <span
  36. class="categ_crumb_panel_btn hand"
  37. :class="{ categ_crumb_panel_btn_only: item.id == chooseCityId }"
  38. v-for="item in cityList"
  39. @click="chooseCity(item.id)"
  40. >
  41. {{ item.name }}
  42. </span>
  43. </div>
  44. </div>
  45. </div>
  46. <!-- 您可以选择以下详细地区 -->
  47. <div class="categ_grey_box clearfix" v-if="secondNav.length > 0">
  48. <div class="categ_grey_head">您可以选择以下详细分类:</div>
  49. <div class="categ_grey_ul clearfix">
  50. <span
  51. :class="['categ_grey_btn hand', { 'categ_grey_btn_only': selectedSecondId == item.category_id }]"
  52. v-for="item in secondNav"
  53. @click="selectSecond(item)"
  54. >
  55. {{ item.alias }}
  56. </span>
  57. </div>
  58. </div>
  59. <!-- 您可以选择以下详细地区 -->
  60. <!-- 供应信息列表 -->
  61. <!-- <div class=" clearfix" v-show="choice_categ_num == 1"> -->
  62. <div class=" clearfix">
  63. <div class="categ_1_index clearfix">
  64. <div class="categ_head_box clearfix_2">
  65. <span class="categ_head_a">供应信息列表</span>
  66. <span class="categ_head_a_more" @click="pageShopList(1)" v-if="pageDataType1.length != 0">
  67. 查看更多 &gt;
  68. </span>
  69. </div>
  70. <div class="categ_table clearfix">
  71. <div class="categ_table_head_box">
  72. <div class="categ_table_td_1">产品图片</div>
  73. <div class="categ_table_td_2">供求信息/公司</div>
  74. <div class="categ_table_td_3">发布时间</div>
  75. <div class="categ_table_td_4">地区</div>
  76. </div>
  77. <ShopNoData v-if="pageDataType1.length == 0" :pagetype="'class'"></ShopNoData>
  78. <div class="categ_table_li" v-for="item in pageDataType1" :key="item.id">
  79. <NuxtLink
  80. :to="getShopPathDetail1(item)"
  81. class="categ_table_li_a"
  82. :title="item.name"
  83. >
  84. <div class="categ_table_td_1">
  85. <img class="categ_table_td_1_img" :src="item.imgurl" alt="item.name">
  86. </div>
  87. <div class="search_table_td_2 ">
  88. <div class="search_table_td_2_in clearfix">
  89. <div class="search_table_td_2_head dot1">
  90. {{ item.name }}
  91. </div>
  92. <div class="search_table_td_2_dot2 dot2">
  93. {{ item.description }}
  94. </div>
  95. </div>
  96. </div>
  97. <div class="categ_table_td_3">{{getTime(item.created_at, 'year', 1)}}</div>
  98. <div class="categ_table_td_4 dot1">{{item.city_name}}</div>
  99. </NuxtLink>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. <div class=" clearfix">
  105. <div class="categ_1_index clearfix">
  106. <div class="categ_head_box clearfix_2">
  107. <span class="categ_head_a">求购信息列表</span>
  108. <span class="categ_head_a_more" @click="pageShopList(2)" v-if="pageDataType2.length != 0">
  109. 查看更多 &gt;
  110. </span>
  111. </div>
  112. <div class="categ_table clearfix">
  113. <div class="categ_table_head_box">
  114. <div class="categ_table_td_1">产品图片</div>
  115. <div class="categ_table_td_2">供求信息/公司</div>
  116. <div class="categ_table_td_3">发布时间</div>
  117. <div class="categ_table_td_4">地区</div>
  118. </div>
  119. <ShopNoData v-if="pageDataType2.length == 0" :pagetype="'class'"></ShopNoData>
  120. <div class="categ_table_li" v-for="item in pageDataType2" :key="item.id">
  121. <NuxtLink
  122. :to="getShopPathDetail1(item)"
  123. class="categ_table_li_a"
  124. :title="item.name"
  125. >
  126. <div class="categ_table_td_1">
  127. <img class="categ_table_td_1_img" :src="item.imgurl" alt="item.name">
  128. </div>
  129. <div class="search_table_td_2 ">
  130. <div class="search_table_td_2_in clearfix">
  131. <div class="search_table_td_2_head dot1">
  132. {{ item.name }}
  133. </div>
  134. <div class="search_table_td_2_dot2 dot2">
  135. {{ item.description }}
  136. </div>
  137. </div>
  138. </div>
  139. <div class="categ_table_td_3">{{getTime(item.created_at, 'year', 1)}}</div>
  140. <div class="categ_table_td_4 dot1">{{item.city_name}}</div>
  141. </NuxtLink>
  142. </div>
  143. </div>
  144. </div>
  145. </div>
  146. <ShopHotNews></ShopHotNews>
  147. </main>
  148. <!-- 页面底部 -->
  149. <HomeFoot></HomeFoot>
  150. </template>
  151. <script setup>
  152. //1.页面必备方法 start ---------------------------------------->
  153. import { ref, onMounted,watch } from 'vue'
  154. import { ElMessage } from 'element-plus'
  155. //1.页面必备方法 end ---------------------------------------->
  156. //2.页面路径 start ---------------------------------------->
  157. //2.1 获得页面数据id
  158. const route = useRoute();
  159. const router = useRouter()
  160. let articleId = 0; //把路径转换为数据id
  161. const targetSegment = getRoutePath(2);//返回第二层的路径id
  162. //通过导航路径反向查询导航id
  163. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  164. method: 'GET',
  165. query: {
  166. 'pinyin': targetSegment,
  167. },
  168. });
  169. if(getRouteId.code == 200){
  170. articleId = getRouteId.data.category_id
  171. }else{
  172. console.log("错误位置:获得页面路径")
  173. }
  174. //2.2 生成面包屑导航
  175. const name = ref('') //当前频道名称
  176. let getPageName = async () => {
  177. const pageName = await requestDataPromise('/web/getOneWebsiteCategory', {
  178. method: 'GET',
  179. query: {
  180. 'catid': articleId
  181. },
  182. });
  183. if (pageName.code == 200) {
  184. name.value = pageName.data.alias
  185. } else {
  186. console.log("错误位置:获取当前频道名称", pageName.message)
  187. }
  188. }
  189. getPageName();
  190. //2.3 获得子栏目列表
  191. const secondNav = ref([]);
  192. const selectedSecondId = ref(route.query.catid);//当前选中了哪个子导航
  193. let getSecondNav = async () => {
  194. const listData = await requestDataPromise('/web/getWebsiteModelCategory', {
  195. method: 'GET',
  196. query: {
  197. 'placeid': 1,
  198. 'pid': articleId,
  199. 'num': 50,
  200. },
  201. });
  202. if (listData.code == 200) {
  203. secondNav.value = listData.data
  204. console.log(secondNav.value)
  205. } else {
  206. console.log("错误位置:获得子级栏目列表")
  207. }
  208. }
  209. getSecondNav();
  210. //2.4 获得cityid
  211. const cityId = ref(route.query.cityid)
  212. //2.页面路径 end ---------------------------------------->
  213. //3.选择商品所在地 start ---------------------------------------->
  214. //3.1 弹出下拉框
  215. const if_categ_crumb_panel = ref(false)//当前商品所在地下拉板
  216. const if_categ_crumb_panel_click = ref(false)//判断是否点击在下拉板内
  217. const btn_if_categ_crumb_panel_fun = () => {//点击下拉btn
  218. if_categ_crumb_panel.value = !if_categ_crumb_panel.value
  219. }
  220. const categ_crumb_panel_btn_blur_fun = () => {//btn失去焦点事件
  221. setTimeout(() => {
  222. if (if_categ_crumb_panel_click.value == true) {
  223. //点击在下拉panel内
  224. } else {
  225. //没点击在下拉panel内
  226. if_categ_crumb_panel.value = false
  227. }
  228. }, 100);
  229. }
  230. //3.2 点击下拉panel
  231. const categ_crumb_panel_focus_fun = () => {
  232. if_categ_crumb_panel_click.value = true
  233. if_categ_crumb_panel.value = true
  234. }
  235. //3.3 下拉panel失去焦点事件
  236. const categ_crumb_panel_blur_fun = () => {
  237. if_categ_crumb_panel_click.value = false
  238. if_categ_crumb_panel.value = false
  239. }
  240. //3.4 获得详细地址列表
  241. const cityName = ref('')
  242. const cityList = ref([])
  243. const chooseCityId = ref('')
  244. let getCityList = async (id) => {
  245. const shengData = await requestDataPromise('/web/selectWebsiteArea', {
  246. method: 'GET',
  247. query: {
  248. 'pid': id,
  249. },
  250. });
  251. if(shengData.code==200){
  252. cityList.value = shengData.data;
  253. cityName.value = shengData.data[0].pid_name;
  254. }else{
  255. ElMessage.error(shengData.message)
  256. }
  257. }
  258. //3.5 初始化的时候先获取一下城市列表
  259. if(cityId.value != undefined){
  260. getCityList(cityId.value);
  261. }
  262. //3.6 选择城市
  263. const chooseCity = (id) => {
  264. chooseCityId.value = id;
  265. router.replace({
  266. path: route.path,
  267. query: {
  268. ...route.query,
  269. select: id
  270. }
  271. })
  272. }
  273. //3.选择商品所在地 end ---------------------------------------->
  274. //4.搜索 start ---------------------------------------->
  275. //4.1 选择一个子导航
  276. const selectSecond = (item) => {
  277. //高亮显示当前选中的子导航
  278. selectedSecondId.value = item.category_id
  279. //带着catid,cityid,select跳转(如果有)
  280. router.push({
  281. path: `/xiangcunshangcheng/${targetSegment}/${item.aLIas_pinyin}/index.html`,
  282. //query: { ...route.query, catid: item.category_id }
  283. })
  284. }
  285. //4.2 页面展示的数据
  286. const pageDataType1 = ref([]);//供应数据
  287. const pageDataType2 = ref([]);//求购数据
  288. //4.3 发起搜索
  289. const pageSearch = async () => {
  290. let params = {
  291. catid:"",//栏目id
  292. city_id:"",//城市id
  293. keyword:"",//搜索关键词 - 该页不需要
  294. page:1,
  295. pageSize:3,
  296. //type_id:1//1:供应 2:求购
  297. }
  298. if(selectedSecondId.value == undefined){
  299. params.catid = articleId
  300. }else{
  301. params.catid = parseFloat(selectedSecondId.value)
  302. }
  303. let routeCiteId = route.query.select;
  304. if(routeCiteId != undefined && routeCiteId != ''){
  305. params.city_id = parseFloat(routeCiteId)
  306. }else{
  307. if(cityId.value == undefined || cityId.value == '' || cityId.value == 'NaN'){
  308. //删除变量params中的city_id参数
  309. delete params.city_id
  310. }else{
  311. params.city_id = parseFloat(cityId.value)
  312. }
  313. }
  314. const pageData = await requestDataPromise('/web/getWebsiteshopList', {
  315. method: 'GET',
  316. query: params,
  317. });
  318. if (pageData.code == 200) {
  319. pageDataType1.value = pageData.data.type1;
  320. pageDataType2.value = pageData.data.type2;
  321. } else {
  322. console.log("错误位置:获得该页面数据失败!")
  323. }
  324. //开始请求数据
  325. console.log(params)
  326. console.log(pageData)
  327. }
  328. //页面初始化的时候调用一下搜索
  329. pageSearch();
  330. //4.4 每次路由一变化就重新请求数据
  331. //4.4.1 监听cityid
  332. watch(() => route.query.cityid, (newVal, oldVal) => {
  333. if(newVal != undefined){
  334. cityId.value = parseFloat(newVal)
  335. getCityList(newVal)
  336. }else{
  337. cityList.value = []
  338. }
  339. pageSearch()
  340. })
  341. //4.4.2 监听catid
  342. // watch(() => route.query.catid, (newVal, oldVal) => {
  343. // pageSearch()
  344. // })
  345. //4.4.3 监听select
  346. //如果路由中存在select参数就忽略cityid
  347. watch(() => route.query.select, (newVal, oldVal) => {
  348. if(newVal != undefined){
  349. pageSearch()
  350. }else{
  351. chooseCityId.value = '';
  352. pageSearch()
  353. }
  354. })
  355. //4.搜索 end ---------------------------------------->
  356. //5.广告 start ---------------------------------------->
  357. //获得所有广告
  358. let adImg1 = ref({})
  359. onMounted(async () => {
  360. const { $webUrl, $CwebUrl } = useNuxtApp();
  361. //从客户端启动广告
  362. //广告1
  363. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=xcw_shoplist_0001`
  364. const responseAd1 = await fetch(url, {
  365. headers: {
  366. 'Content-Type': 'application/json',
  367. 'Userurl': $CwebUrl,
  368. 'Origin': $CwebUrl
  369. }
  370. });
  371. const resultAd1 = await responseAd1.json();
  372. adImg1.value = resultAd1.data[0];
  373. })
  374. //5.广告 end ---------------------------------------->
  375. //6.跳转到列表页 start ---------------------------------------->
  376. const pageShopList = (type) => {
  377. const { cityid, select } = route.query
  378. const queryParams = {
  379. ...(cityid && { cityid }),
  380. ...(select && { select })
  381. }
  382. if(type == 1){
  383. //type==1 跳转到供应列表页
  384. const targetPath = `/xiangcunshangcheng/${targetSegment}/gongying/list-1.html`
  385. router.push({
  386. path: targetPath,
  387. query: queryParams
  388. })
  389. }else{
  390. //type==2 跳转到求购列表页
  391. const targetPath = `/xiangcunshangcheng/${targetSegment}/qiugou/list-1.html`
  392. router.push({
  393. path: targetPath,
  394. query: queryParams
  395. })
  396. }
  397. }
  398. //6.跳转到列表页 end ---------------------------------------->
  399. </script>
  400. <style lang="less" scoped>
  401. @import '@/assets/css/shop/class.less';
  402. </style>